package com.oscarmovie.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.oscarmovie.Constants;
import com.oscarmovie.model.Award;
import com.oscarmovie.model.Movie;
import com.oscarmovie.model.Mpac;
import com.oscarmovie.model.Calendar;
import com.oscarmovie.model.Person;
import com.oscarmovie.service.MovieService;
import com.oscarmovie.service.MpacService;
import com.oscarmovie.service.CalendarService;
import com.oscarmovie.service.PersonService;
import com.oscarmovie.service.AwardService;

public class MpacAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private MpacService mpacService;
	
	private MovieService movieService;
	private PersonService personService;
	private AwardService awardService;
	private CalendarService calendarService;
	
	private Mpac mpac;
	private List<Mpac> mpacs;
	
	private List<Movie> movies;
	private List<Award> awards;
	private List<Person> persons;
	private List<Calendar> calendars;
	private int calendarId;
	private Person person;//for search keyword;

	
	public String execute() throws Exception {
		throw new Exception("Please specify method name!");
	}
	public String add() throws Exception {
		setMpac(null);
		return Constants.ADD;
	}
	public String edit() throws Exception {
		loadAll();
		load();
		return Constants.EDIT;
	}
	public String save() throws Exception {
		mpacService.save(mpac);
		return edit();
	}
	public String delete() throws Exception {
		mpacService.delete(mpac);
		return "success";
	}
	public String load() throws Exception {
		this.setMpac(mpacService.load(mpac.getId()));
		return SUCCESS;
	}
	
	public String loadAll() throws Exception {
		this.mpacs = mpacService.loadAll();
		
		if(person!=null && !"".equals(person.getName())){
			Person p = new Person();
			String n = person.getName().trim();
			p.setName(n);
			p.setNameCn(n);
			
			persons = personService.loadAll(p);
		} else {
			persons = personService.loadAll();
		}
		this.awards = awardService.loadAll();
		this.calendars = calendarService.loadAll();
		
		return SUCCESS;
	}
	public String select() throws Exception {
		loadAll();
		return Constants.SELECT;
	}
	public List<Mpac> getMpacs() {
		return mpacs;
	}

	public void setMpacService(MpacService mpacService) {
		this.mpacService = mpacService;
	}

	public void setMpac(Mpac mpac) {
		this.mpac = mpac;
	}

	public Mpac getMpac() {
		return mpac;
	}
	public void setAwardService(AwardService awardService) {
		this.awardService = awardService;
	}
	public AwardService getAwardService() {
		return awardService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setCalendarService(CalendarService calendarService) {
		this.calendarService = calendarService;
	}
	public CalendarService getCalendarService() {
		return calendarService;
	}
	public void setCalendars(List<Calendar> calendars) {
		this.calendars = calendars;
	}
	public List<Calendar> getCalendars() {
		return calendars;
	}
	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}
	public List<Person> getPersons() {
		return persons;
	}
	public void setAwards(List<Award> awards) {
		this.awards = awards;
	}
	public List<Award> getAwards() {
		return awards;
	}
	public void setMovieService(MovieService movieService) {
		this.movieService = movieService;
	}
	public MovieService getMovieService() {
		return movieService;
	}
	public void setMovies(List<Movie> movies) {
		this.movies = movies;
	}
	public List<Movie> getMovies() {
		return movies;
	}
	
	public void setCalendarId(int calendarId) {
		this.calendarId = calendarId;
	}
	public int getCalendarId() {
		return calendarId;
	}
	public void setPerson(Person person) {
		this.person = person;
	}
	public Person getPerson() {
		return person;
	}
}
